
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region OrderStateChanges Model -(by fangyifeng at 2007-09-14 12:24:14)

	/// <summary>
	/// OrderStateChanges object'OrderStateChanges'.
	/// </summary>
	[Serializable]
	public class OrderStateChanges : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected DateTime _editDate;
		protected string _changedMemo;
		protected ProductOrder _productOrder;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public OrderStateChanges() { }

		public OrderStateChanges( DateTime editDate, string changedMemo, ProductOrder productOrder )
		{
			this._editDate = editDate;
			this._changedMemo = changedMemo;
			this._productOrder = productOrder;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual DateTime EditDate
		{
			get { return _editDate; }
			set { _editDate = value; }
		}

		public virtual string ChangedMemo
		{
			get { return _changedMemo; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for ChangedMemo", value, value.ToString());
				_changedMemo = value;
			}
		}

		public virtual ProductOrder ProductOrder
		{
			get { return _productOrder; }
			set { _productOrder = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is OrderStateChanges))
				throw new InvalidCastException("This object is not of type OrderStateChanges");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((OrderStateChanges)obj).Id);
					break;
				case "EditDate":
					relativeValue = this.EditDate.CompareTo(((OrderStateChanges)obj).EditDate);
					break;
				case "ChangedMemo":
					relativeValue = (this.ChangedMemo != null) ? this.ChangedMemo.CompareTo(((OrderStateChanges)obj).ChangedMemo) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (OrderStateChanges.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
